package com.gxa.saas.portal.util;

import com.gxa.saas.portal.service.impl.AddJestServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.logging.Logger;
import org.mybatis.logging.LoggerFactory;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.util.concurrent.TimeUnit;


/**
 * @Auther: pengxtao
 * @Date: 2022/7/21
 * 定时任务设置每隔两小时向es插入一次数据
 */
@Configuration
@EnableScheduling
@Slf4j
public class ScheduledTaskConfig {
    private static final Logger LOGGER = LoggerFactory.getLogger(ScheduledTaskConfig.class);

    // fixrate属性是调用开始到后一个次用之间的间隔，所以如果间隔小，但是方法耗时，方法会直接执行
    @Scheduled(fixedRate = 1000L)
    public void task1() throws InterruptedException {
        AddJestServiceImpl purchaseDetailService= (AddJestServiceImpl) ApplicationContextUtil.getBean("addJestService");
        purchaseDetailService.add();
        log.info("---------执行了插入es方法-----------------");
        TimeUnit.SECONDS.sleep(60*60*2);
    }
}
